/*package com.clinic.logic.report;

import java.util.ArrayList;
import java.util.List;

import net.sf.dynamicreports.jasper.builder.JasperReportBuilder;
import net.sf.dynamicreports.report.builder.DynamicReports;
import net.sf.dynamicreports.report.builder.column.Columns;
import net.sf.dynamicreports.report.builder.column.TextColumnBuilder;
import net.sf.dynamicreports.report.builder.component.Components;
import net.sf.dynamicreports.report.builder.component.TextFieldBuilder;
import net.sf.dynamicreports.report.builder.datatype.DataTypes;
import net.sf.dynamicreports.report.constant.HorizontalAlignment;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.clinic.accessor.db.DrugStockAccessor;
import com.clinic.entity.db.DrugStock;
import com.clinic.entity.param.Index;
import com.clinic.entity.report.RptDrug;
import com.clinic.util.RptStyleUtil;

@Component
public class ReportLogic {
	
	@Autowired
	private DrugStockAccessor drugStockAccessor;
	
	public JasperReportBuilder getDrugStockReport(Index index) {
		List<DrugStock> drugStockList = drugStockAccessor.getDrugStocks(index);
		List<RptDrug> dataList = new ArrayList<RptDrug>();
		for (DrugStock drugStock : drugStockList) {
			RptDrug rptDrug = new RptDrug();
			rptDrug.setId(drugStock.getDrugStockId());
			rptDrug.setName(drugStock.getDrug().getName());
			rptDrug.setBrand(drugStock.getDrug().getBrand().getName());
			rptDrug.setStrength(drugStock.getDrug().getWeight() + " mg");
			rptDrug.setStock(drugStock.getAmount());
			rptDrug.setExpireDate(drugStock.getExpireDate());
			dataList.add(rptDrug);
		}
		return getDrugStockBuilder(dataList);
	}
	
	public JasperReportBuilder getDrugStockBuilder(List<RptDrug> dataList) {
		TextColumnBuilder<Integer> rowNumberColumn = Columns.reportRowNumberColumn("No.")
				.setFixedColumns(2)
				.setHorizontalAlignment(HorizontalAlignment.CENTER);

		// generate columns
		TextColumnBuilder<String> colName = Columns.column("Name", "name", DataTypes.stringType());
		TextColumnBuilder<String> colBrand = Columns.column("Brand", "brand", DataTypes.stringType());
		TextColumnBuilder<String> colStrength = Columns.column("Strength", "strength", DataTypes.stringType());
		TextColumnBuilder<Integer> colStock = Columns.column("Stock", "stock", DataTypes.integerType());
		
		// title
		TextFieldBuilder<String> title1 = Components.text("Dr. W. P. Sanjeewa Withana")
				.setHorizontalAlignment(HorizontalAlignment.CENTER)
				.setStyle(RptStyleUtil.subheaderSecondary());
		TextFieldBuilder<String> title2 = Components.text("Medical Officer - MBBS (Sri Lanka) - SLMC Reg.No: 25140")
				.setHorizontalAlignment(HorizontalAlignment.CENTER)
				.setStyle(RptStyleUtil.itemTitleSecondary());
		TextFieldBuilder<String> title3 = Components.text("Dispensary & Surgery")
				.setHorizontalAlignment(HorizontalAlignment.CENTER)
				.setStyle(RptStyleUtil.itemTitle());
		TextFieldBuilder<String> title4 = Components.text("No. 491, Iriyawatiya, Kelaniya. - Tel.No.: 718 65 62 62")
				.setHorizontalAlignment(HorizontalAlignment.CENTER)
				.setStyle(RptStyleUtil.itemTitleNormal());
		
		TextFieldBuilder<String> ttlPageMain = Components.text("Drug Stock Report").setStyle(RptStyleUtil.subheader());
		
		JasperReportBuilder report = DynamicReports.report();// a new report
		report
			.columns(rowNumberColumn, colName, colBrand, colStrength, colStock)
			.setColumnTitleStyle(RptStyleUtil.tblColumn())
			.highlightDetailEvenRows()
			.groupBy(colBrand)
			.title(title1, title2, title3, title4, ttlPageMain)// title of the report
			.pageFooter(Components.pageXofY());// show page number on the page footer
//			.setDataSource(dataList);
		return report;
	}

}*/
